//
//  WBStatusCell.swift
//  CZweibo
//
//  Created by jyh on 2017/12/12.
//  Copyright © 2017年 jyh. All rights reserved.
//

import UIKit
import SDWebImage

class WBStatusCell: UITableViewCell {

    // 头像
    @IBOutlet weak var iconView: UIImageView!
    // 昵称
    @IBOutlet weak var nameLabel: UILabel!
    // 会员图标
    @IBOutlet weak var memberIconView: UIImageView!
    // 时间
    @IBOutlet weak var timeLabel: UILabel!
    // 来源
    @IBOutlet weak var sourceLabel: UILabel!
    // VIP图标
    @IBOutlet weak var vipIconView: UIImageView!
    // 正文
    @IBOutlet weak var statusLabel: UILabel!
    // 底部工具栏
    @IBOutlet weak var toolBar: WBStatusToolBar!
    // 配图视图
    @IBOutlet weak var pictureView: WBStatusPictureView!
    
    var viewModel: WBStatusViewModel?  {
        
        didSet {
            /*
             var id:	Int64 = 0  //用户UID
             var screen_name: String?	// string 用户昵称
             var profile_image_url: String?	//string	用户头像地址（中图），50×50像素
             var verified_type: Int = 0 // vip图标
             avatar_enterprise_vip
             avatar_vip
             avatar_grassroot
             var mbrank: Int = 0 // 会员等级
             
             created_at
             */
            
   
            iconView.hg_setImage(urlStr: viewModel?.status.user?.profile_image_url, placeholderImage: nil, cornerRadius: true)
            
            vipIconView.image = viewModel?.vipIcon
            memberIconView.image = viewModel?.mbrankIcon
            nameLabel.text = viewModel?.status.user?.screen_name
            sourceLabel.text = viewModel?.status.source
            timeLabel.text = viewModel?.status.created_at
            statusLabel.text = viewModel?.status.text
            toolBar.viewModel = viewModel
            
            pictureView.heightCons.constant = viewModel?.pictureViewSize.height ?? 0
            
            // 测试4张图的代码
//            if viewModel?.status.pic_urls?.count ?? 0 > 4 {
//                var picURLS = viewModel!.status.pic_urls!
//                
//                picURLS.removeSubrange((picURLS.startIndex + 4)..<picURLS.endIndex)
//                
//                pictureView.urls = picURLS
//            } else {
//            
//            pictureView.urls = viewModel?.status.pic_urls
//            }
            
            pictureView.urls = viewModel?.status.pic_urls
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
